package com.shr.lease.web.app.service.impl;

import com.shr.lease.common.context.LoginUserContext;
import com.shr.lease.model.entity.ViewAppointment;
import com.shr.lease.web.app.mapper.ViewAppointmentMapper;
import com.shr.lease.web.app.service.ApartmentInfoService;
import com.shr.lease.web.app.service.ViewAppointmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shr.lease.web.app.vo.apartment.ApartmentDetailVo;
import com.shr.lease.web.app.vo.apartment.ApartmentItemVo;
import com.shr.lease.web.app.vo.appointment.AppointmentDetailVo;
import com.shr.lease.web.app.vo.appointment.AppointmentItemVo;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liubo
 * @description 针对表【view_appointment(预约看房信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ViewAppointmentServiceImpl extends ServiceImpl<ViewAppointmentMapper, ViewAppointment>
        implements ViewAppointmentService {

    @Resource
    private ViewAppointmentMapper viewAppointmentMapper;
    @Resource
    private ApartmentInfoService apartmentInfoService;


    @Override
    public List<AppointmentItemVo> listAppointmentItemVo() {
        return viewAppointmentMapper.listAppoinmentItemVo(LoginUserContext.getLoginUser().getUserId());
    }

    @Override
    public AppointmentDetailVo getDetailById(Long id) {
        //预约信息
        ViewAppointment viewAppointment = viewAppointmentMapper.selectById(id);
        //公寓基本信息
        ApartmentDetailVo apartmentDetailVo = apartmentInfoService.getDetailById(viewAppointment.getApartmentId());
        ApartmentItemVo apartmentItemVo = ApartmentItemVo.builder().build();
        BeanUtils.copyProperties(apartmentDetailVo, apartmentItemVo);
        //结果拼接
        AppointmentDetailVo appointmentDetailVo = AppointmentDetailVo.builder()
                .apartmentItemVo(apartmentItemVo)
                .build();
        BeanUtils.copyProperties(viewAppointment, appointmentDetailVo);
        return appointmentDetailVo;
    }
}




